package com.newcoder.controller;

import com.newcoder.entity.Comment;
import com.newcoder.service.impl.CommentServiceImpl;
import com.newcoder.util.ResponseWrapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjh
 * @since 2024-12-04 10:03:25
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentServiceImpl commentService ;

    @ApiOperation("新增评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "comment",value = "用户评论表单"),
    })
    @PostMapping("/insertComment")
    public ResponseWrapper insertComment(@RequestParam(name = "discussPostId")Integer discussPostId, @RequestBody Comment comment){
        ResponseWrapper wrapper = commentService.insertComment(discussPostId, comment);
        return wrapper;
    }

    @ApiOperation("删除评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "评论id"),
    })
    @GetMapping("/deleteCommentById")
    public ResponseWrapper deleteCommentById(@RequestParam(name = "id")Integer id){
        ResponseWrapper wrapper = commentService.deleteCommentById(id);
        return wrapper;
    }

    @ApiOperation("查找评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "评论id"),
    })
    @GetMapping("/selectCommentById")
    public ResponseWrapper selectCommentById(@RequestParam(name = "id")Integer id){
        ResponseWrapper wrapper = commentService.selectCommentById(id);
        return wrapper;
    }

    @ApiOperation("查询文章一级评论，评论文章的评论，无需分页，加载全部（前端可以使用懒加载）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entityType", value = "评论类别：1代表帖子,2评论", defaultValue = "1"),
            @ApiImplicitParam(name = "entityId", value = "被评论的帖子id"),
            @ApiImplicitParam(name = "currentPage",value = "当前页码数,只有一页",defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "MAX_SIZE"),
    })
    @GetMapping("/selectDiscussPostAllComments")
    public ResponseWrapper selectDiscussPostAllComments(@RequestParam(name = "entityId")Integer entityId){
        ResponseWrapper wrapper = commentService.selectDiscussPostAllComments(entityId);
        return wrapper;
    }

    @ApiOperation("文章二级评论，评论用户评论的评论，分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entityType", value = "评论类别：1代表帖子,2评论", defaultValue = "2"),
            @ApiImplicitParam(name = "entityId", value = "被评论的评论id"),
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
    })
    @GetMapping("/selectCommentsPage")
    public ResponseWrapper selectCommentsPage(@RequestParam(name = "entityId")Integer entityId,
                                          @RequestParam(name = "currentPage",defaultValue = "1")Integer currentPage,
                                          @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize){
        ResponseWrapper wrapper = commentService.selectCommentsPage(entityId, currentPage, pageSize);
        return wrapper;
    }
}
